package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.entity.Scenic;
import com.ruoyi.system.mapper.ScenicDao;
import com.ruoyi.system.service.ScenicService;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Service;
/*******************    💫 Codegeex Inline Diff    *******************/
/**
 * Auto created by codeAppend plugin
 */
@Service
public class ScenicServiceImpl extends ServiceImpl<ScenicDao, Scenic> implements ScenicService {

    // use "baseMapper" to call jdbc
    // example: baseMapper.insert(entity);
    // example: baseMapper.selectByPage(params);

    @Override
    public boolean createScenic(Scenic scenic) {
        Scenic s = new Scenic();
        s.setName(scenic.getName());
        s.setImage(scenic.getImage());
        s.setMsg(scenic.getMsg());
        s.setPrincipal(scenic.getPrincipal());
        s.setPrincipalPhone(scenic.getPrincipalPhone());
        return baseMapper.insert(scenic) > 0;
    }

    @Override
    public boolean deleteScenicById(Long id) {
        return baseMapper.deleteById(id) > 0;
    }

    @Override
    public boolean updateScenic(Scenic scenic) {
        LambdaQueryWrapper<Scenic> lqw = new LambdaQueryWrapper();
        lqw.eq(Scenic::getId, scenic.getId());
        Scenic s = baseMapper.selectOne(lqw);
        if (s == null){
            throw new RuntimeException("Scenic not found");
        }
        s.setName(scenic.getName());
        s.setImage(scenic.getImage());
        s.setMsg(scenic.getMsg());
        s.setPrincipal(scenic.getPrincipal());
        s.setPrincipalPhone(scenic.getPrincipalPhone());
        return baseMapper.updateById(scenic) > 0;
    }

    @Override
    public Scenic getScenicById(Long id) {
        return baseMapper.selectById(id);
    }
}
